//
//  MyHomeCell.swift
//  DaRings
//
//  Created by 易先生 on 2022/10/27.
//

import UIKit
import MYModule

class MyHomeTableCell: TableViewCell {

    override func makeUI() {
        super.makeUI()
        
        contentView.backgroundColor = UIColor.background
      
        
        contentView.addSubview(titleLabel)
        contentView.addSubview(iconView)
        contentView.addSubview(brage)
        contentView.addSubview(nextIconView)
        

        iconView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.leading.equalToSuperview().offset(20)
            make.size.equalTo(CGSize(width: 40, height: 40))
            make.top.equalToSuperview().offset(20)
            make.bottom.equalToSuperview().offset(-20)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.leading.equalTo(iconView.snp.trailing).offset(10)
        }
        
        brage.snp.makeConstraints { make in
            make.left.equalTo(titleLabel.snp.right).offset(5)
            make.size.equalTo(6)
            make.bottom.equalTo(titleLabel.snp.top)
        }
        
        nextIconView.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-28)
            make.centerY.equalToSuperview()
        }
        
    }
    
    public func bind(to item: MyHomeItem) {
        titleLabel.text = item.type.label
        iconView.image = UIImage(named: item.type.icon)
        brage.isHidden = !item.brage
        
        if item.type == .firmware {
            
            log.debug("\(item.isHidden)")
            log.debug("\(item.brage)")
            
        }
        
      
    }
    
    private lazy var titleLabel: Label = {
        let titleLabel = Label()
        titleLabel.textColor = UIColor.assist_222222
        titleLabel.font =  Fonts.list_view_title()
        return titleLabel
    }()
    
    private lazy var iconView: ImageView = {
        let iconView = ImageView()
        iconView.contentMode = .scaleAspectFit
        return iconView
    }()
    
    private lazy var brage: View = {
        
        let brage = View()
        brage.backgroundColor = UIColor.subTheme
        brage.cornerRadius = 3.0
        return brage
        
    }()
    
    private lazy var nextIconView: ImageView = {
        let nextIconView = ImageView()
        nextIconView.image = UIImage(named: "ic_continue")
        return nextIconView
    }()

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
